import redis
from server.conf import setting

class RedisHelper(object):
    def __init__(self):
        self.__conn = redis.Redis(host=setting.RedisServer,port=setting.RedisPort)
        self.pubchan = setting.RedisPubChannel
        self.subchan = setting.RedisSubChannel
    
    def get(self,key):
        return self.__conn.get(key)
    
    def set(self,key,value):
        return self.__conn.set(key,value)
    
    def keys(self,pattern='*'):
        return self.__conn.keys(pattern)
    
    def publish(self,msg):
        return self.__conn.publish(self.pubchan, msg)
    
    def subscribe(self):
        pub = self.__conn.pubsub()
        pub.subscribe(self.subchan)
        pub.parse_response()
        return pub